<template>
  <div>
    <div>
      <span>书名</span>
      <input v-model="book.name" />
    </div>
    <div>
      <span>作者</span>
      <input v-model="book.author" />
    </div>
    <div>
      <span>价格</span>
      <input v-model="book.price" />
    </div>
    <div>
      <button @click="update"> 提交</button>
    </div>
  </div>
</template>

<script>
export default {

  created () {
    this.getById()
  },

  data () {
    return {
      book: {}
    }
  },
  methods: {
    update () {
      this.book.id = this.$route.query.id;
      this.axios.post("http://localhost:8082/book/update", this.book).then(res => {
        console.log(res);
        if (res.data.affectedRows = 1) {
          this.$router.push("/")
        }
      })
    },
    getById () {
      let id = this.$route.query.id;
      this.axios.post("http://localhost:8082/book/getById", { id: id }).then(res => {
        this.book = res.data[0]
      })
    }
  }

}
</script>

<style lang="less" scoped>
</style>